import * as actionType from './constants.js';
import {reqBanner ,reqPersonalized,reqGetHotSingerListRequest,reqChangeSingerList,reqSongSheetDetail} from '../../../api/index'

//主页数据
export const changeBanners = (data) => {
    // console.log("进去成功...............");
    return {
        type: actionType.CHANGE_BANNERS,
        data: data
    }
}
export const changePersonalized = (data) => {
    // console.log("进去成功...............");
    return {
        type: actionType.CHANGE_PERSONALIZED,
        data: data
    }
}
export const changeHotSinger = (data) =>{
    // console.log("进去成功...............");
    return {
        type: actionType.GET_HOTSINGERLISTREQUEST,
        data: data
    }
}
export const changeChangeSingerList = (data) =>{
    // console.log("进去成功...............");
    return {
        type: actionType.GET_CHANGESINGERLIST,
        data: data
    }
}
export const changeSongSheetDetail = (data)=>{
    // console.log('进去成功.....')
    return{
        type: actionType.GET_SONGSHEETDETAIL,
        data:data
    }
}

export const setNum = (data) =>{
    return{
        type:actionType.SET_NUM,
        data:data
    }
}
export const setIndex = (data) =>{
    return{
        type:actionType.SET_INDEX,
        data:data
    }
}
export const getBanners = () =>{
    return (dispatch) =>{
        reqBanner()
            .then((res) =>{
                // console.log(res,'first');
                dispatch(changeBanners(res.data.banners))
            })
            .catch((e) =>{
                console.log(e)
            })
    }
}

export const getPersonalized = () =>{
    return (dispatch) =>{
        reqPersonalized()
            .then((res) =>{
                // console.log(res,'reqPersonalized');
                dispatch(changePersonalized(res.data.result))
            })
            .catch((e) =>{
                console.log(e,'error')
            })
    }

}

export const getHotSingerListRequest = (rank) =>{
    return (dispatch) =>{
        reqGetHotSingerListRequest(rank)
            .then((res) =>{
                // console.log(res,'hotsinger');
                dispatch(changeHotSinger(res.data.artists))
            })
            .catch((e) =>{
                console.log(e,'error')
            })
    }
}

export const getChangeSingerList = (UrlA,UrlB) =>{
    return (dispatch) =>{
        reqChangeSingerList(UrlA,UrlB)
            .then((res) =>{
                // console.log(res,'hotsinger');
                dispatch(changeChangeSingerList(res.data.artists))
            })
            .catch((e) =>{
                console.log(e,'error')
            })
    }
}
export const getSongSheetDetail = (id) =>{
    return (dispatch) =>{
        reqSongSheetDetail(id)
            .then((res) =>{
                // console.log(res,'hotsinger');
                dispatch(changeSongSheetDetail(res.data.playlist))
            })
            .catch((e) =>{
                console.log(e,'error')
            })
    }
}